<template>
  <div class="my">
    <img :src="userInfo.profile?.avatarUrl" alt="">
   <div class="name">{{userInfo.profile?.nickname}}</div>
    <van-button @click="logout">退出登录</van-button>
  </div>
</template>


<script setup>
import {getCurrentInstance, onMounted, ref} from "vue";
import api from "../../utils/api.js";
import router from "../../router/index.js";
const {proxy} = getCurrentInstance();
// 用户基本信息
const userInfo = ref({});
// 获取用户基本信息
const getUserInfo = async () => {
  // 获取用户详情
  let result = await proxy.$Request('/login/status');
  console.log(result)
  if(result.data.code === 200) {
    console.log(result)
    // 获取用户详情
    // let res = await proxy.$Request(`/user/detail?uid=${result.data?.account?.id}`);
    let res = await proxy.$Request(`/user/account`);
    console.log(res)
    userInfo.value = res
  }

}
// 退出登录
const logout = async () => {
  let res = await proxy.$Request('/logout');
  api.refreshLogin();
  router.push('/login');
}
// 获取用户信息 , 歌单，收藏，mv, dj 数量
// const a = async () => {
//   let result = await proxy.$Request('/user/subcount');
//   console.log(result)
// }
onMounted(() => {
  // 获取用户基本信息
  getUserInfo();
})
</script>


<style scoped lang="scss">
.my{
  margin-top: 20%;
  display: flex;
  flex-direction: column;
  align-items: center;
  .name{
    margin: 30px 0;
  }
}
</style>
